<?php echo $header; echo $sidebar ; 
//echo "<pre>";print_r($organization);exit;
function RecursiveList($array) {
    if (count($array)) {
        echo "\n<ul>\n"; 
        //echo "<pre>";print_r($array);
        foreach ($array as $vals) {
            echo "<li id=\"node_".$vals['id']."\">";
            echo '<a href="#">';
            echo $vals['first_name'];
            echo "</a>";
            $cls = new admin_hrm_timesheet_model();
           	$child = $cls->admin_hrm_timesheet_model->get_Users($vals['id']);
           	//echo "<pre>";print_r($child);
            if (count($child)) { 
                RecursiveList($child); 
            }
            echo "</li>\n";
        }
        echo "</ul>\n"; 
    }
} ?>
<div class="span10 content">
	<?php echo $hugemenu ?>
	<div class="row-fluid">
	<div class="span2">
		<h1><?php //echo lang('Organization');?>Organization</h1>
	</div>
	<div class="content">
	<span  style="margin-left: 50px;">Expand to</span> <input style="margin-top:10px;" type="text" id="in-ex" value="1" class="input-mini">
	<span style="margin: 0 5px 0 5px;">level</span> 
	<a href="#" class="btn btn-primary" id="bt-ex" style="border-radius: 4px !important;margin-right: 5px;">Update</a>
	<a href="#" class="btn btn-warning" id="bt-ex-all" style="border-radius: 4px !important;margin-right: 5px;">Expand All</a>
	<a href="#" class="btn btn-success" id="bt-cl" style="border-radius: 4px !important;">Collapse to 1 level</a>
	</div>
	</div>
	<div id="otree" style="float: default;">
	<?php RecursiveList($organization); ?>
	</div>
	
</div>
<script>
jQuery(function($) {
	var depth = 1;
	
	$("#otree").jstree({ 
		"plugins" : [ "html_data","themes"],
		
	});
	$("#otree").bind('loaded.jstree', function(e, data) {
		 

		 data.inst.get_container().find('li').each(function(i){

			 if (data.inst.get_path($(this)).length <= depth) {
		            data.inst.open_node($(this));
		        }
			 
		    });
		    
		});

	$("#otree").bind('refresh.jstree', function(e, data) {
		 

		 data.inst.get_container().find('li').each(function(i){

			 if (data.inst.get_path($(this)).length <= depth) {
		            data.inst.open_node($(this));
		        }
			 
		    });
		    
		});
	
	$('#bt-ex').click(function(){
		var inex = $('#in-ex').val();
		inex = inex - 0;
		 depth = inex;
		
		 $("#otree").jstree('close_all');
		$("#otree").jstree('refresh',1);
		
		});
	$('#bt-ex-all').click(function(){

		$("#otree").jstree('open_all');
		
		});
	$('#bt-cl').click(function(){

		$("#otree").jstree('close_all');
		depth = 1;
		$("#otree").jstree('refresh',1);
		});
});

</script>
<?php echo $footer ?>